﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel.DomainServices.Server;

namespace MVVMtutorialAdvanced.Web
{
	//[MetadataType(typeof(BookDTOMetadata))]
	//public partial class BookDTO
	//{
	//  internal sealed class BookDTOMetadata
	//  {
	//    [Include]
	//    [Association("Book_Author", "Id", "BookId")] //BookDTO.Id -> BookAuthorDTO.BookId
	//    [Composition]
	//    public ICollection<BookAuthorDTO> Authors { get; set; }
	//  }
	//}

	public class BookDTO
	{
		public BookDTO()
		{
			Authors = new List<BookAuthorDTO>();
		}
		
		[Key]
		[Display(Order = 1, AutoGenerateField = false)]
		public int Id { get; set; }

		[Required(AllowEmptyStrings = false, ErrorMessage = "Muss- Feld")]
		[StringLength(65, ErrorMessage = "Maximal 65 Buchstaben")]
		[Display(Name = "Titel", Description = "Dies ist der Titel")]
		[RegularExpression(@"[\w\d \\\/\:\-\.\,\!\?]*", ErrorMessage = "Nur Buchstaben, Zahlen und .,:-!?")]
		public string Title { get; set; }

		[Display(Name = "Preis", Description = "Dies ist der Preis", AutoGenerateField = false)]
		[DataType(DataType.Currency)]
		[Range(0D, 9999D, ErrorMessage = "zwischen 0 und 9999")]
		public decimal Price { get; set; }

		[Display(Name = "Autoren", Description = "Dies sind die Autoren", AutoGenerateField = false)]
		[Include]
		[Association("Book_Author", "Id", "BookId")] //BookDTO.Id -> BookAuthorDTO.BookId
		[Composition]
		public ICollection<BookAuthorDTO> Authors { get; set; }

		[Display(Name = "Ausverkauft", Description = "Ausverkauft wenn markiert", AutoGenerateField = false)]
		public bool IsOutOfStock { get; set; }

		[Display(Name = "Veröffentlicht", Description = "Datum der Veröffentlichung", AutoGenerateField = false)]
		public DateTime? Release { get; set; }

		//Due to an error in the April 2010 ComboBox, NULL cannot be used  (int?)
		//https://connect.microsoft.com/VisualStudio/feedback/details/597689/silverlight-combobox-binding-drops-after-null-binding
		[Display(Name = "Land", Description = "Veröffentlicht in", AutoGenerateField = false)]
		public int CountryId { get; set; }

		[Display(Name = "Umschlag", Description = "Dies ist ein Thumbnail des Umschlags", AutoGenerateField = false)]
		public byte[] Cover { get; set; }
	}
}